package com.fenghongzhang.club_2303.test

import MyAdapter
import android.app.Activity
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.fenghongzhang.club_2303.R
import com.fenghongzhang.club_2303.test.rv.ItemBean
import com.flyjingfish.android_aop_core.annotations.Delay
import com.flyjingfish.android_aop_core.annotations.OnLifecycle
import kotlin.random.Random


class TestActivity : AppCompatActivity() {

    private lateinit var recyclerView: RecyclerView
    private lateinit var adapter: MyAdapter
    private lateinit var dataList: MutableList<ItemBean>

    // 示例图片资源（替换为自己项目的图片）
    private val imageRes = listOf(
        "https://jystest-resource.iwubida.com/smartdms/2023/11/fJNsZHQynflE7uDHZ67mx.jpg",
        "https://jystest-resource.iwubida.com/smartdms/2023/11/w-y4v8VGgsUqqNj_2apqZ.jpg",
        "https://jystest-resource.iwubida.com/smartdms/2023/11/DIjcFdd60o18l3mBqQ-OT.jpg"
    )



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_test)

        // 初始化数据
        initData()

        // 初始化RecyclerView
        recyclerView = findViewById(R.id.recycler_view)
        recyclerView.layoutManager = LinearLayoutManager(this)
        adapter = MyAdapter()
        recyclerView.adapter = adapter
        adapter.updateData(dataList)

        // 刷新按钮点击事件
        findViewById<Button>(R.id.btn_refresh).setOnClickListener {
            val randomId = Random.nextInt(5)
            val newText = "更新文字 ${System.currentTimeMillis()}"
            adapter.updateItemPartially(itemId = randomId, newText = newText)

        }
    }

    private fun initData() {
        dataList = listOf(
            ItemBean(0, imageRes[0], "初始文字 0"),
            ItemBean(1, imageRes[1], "初始文字 1"),
            ItemBean(2, imageRes[2], "初始文字 2"),
        ).toMutableList()
    }
    @CustomIntercept("我是自定义数据")
    fun onCustomIntercept(){
        println("onCustomIntercept")
    }


    fun test(){

    }

    @CustomIntercept("我是自定义数据333333")
    fun onCustomIntercept1(){
        println("onCustomIntercept")
    }


    override fun onStart() {
        super.onStart()
        println("onStart")
    }

    @OnLifecycle(Lifecycle.Event.ON_START)
    fun dalay(){
        println("dalay")
    }

    @IsLogin
    override fun onResume() {
        super.onResume()
        println("onResume")
    }

    @IsLogin
    override fun onPause() {
        super.onPause()
        println("onResume")
    }

}